# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def isValidBST(self, root: TreeNode) -> bool:
        self.res = []
        if root:
            self.search(root)
        if len(self.res) == 1:
            return True
        for i in range(len(self.res)-1):
            if self.res[i] >= self.res[i+1]:
                return False
        else:
            return True

    def search(self, root: TreeNode):
        if root.left:
            self.search(root.left)
        self.res.append(root.val)
        if root.right:
            self.search(root.right)

